package com.lagou.framework.coyote;


import com.lagou.framework.common.HttpServlet;
import com.lagou.framework.common.Request;
import com.lagou.framework.common.Response;
import com.lagou.framework.container.Service;

import java.net.Socket;
import java.util.Map;
import java.util.Objects;

/**
 * @author srh
 * @date 2020/03/31
 **/
public class Processor extends Thread {

    private Socket socket;

    public Processor(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            System.out.println(Thread.currentThread().getName());
            // 封装Request对象和Response对象
            Request request = new Request(socket.getInputStream());
            Response response = new Response(socket.getOutputStream());

            Service.getInstance().doService(request, response);

            socket.close();

        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
